package com.ruoyi.web.controller.meterread;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.WaterWeeklyUsage;
import com.ruoyi.system.domain.vo.WaterUserMeterVO;
import com.ruoyi.system.service.IWaterUserService;
import com.ruoyi.system.service.IWaterWeeklyUsageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 周用水量汇总Controller
 *
 * @author ruoyi
 * @date 2025-09-20
 */
@RestController
@RequestMapping("/meterread/weekusage")
public class WaterWeeklyUsageController extends BaseController
{
    @Autowired
    private IWaterUserService waterUserService;
    @Autowired
    private IWaterWeeklyUsageService waterWeeklyUsageService;

    /**
     * 查询远传表档案列表
     */
    @PreAuthorize("@ss.hasPermi('meterread:weekusage:list1')")
    @GetMapping("/list")
    public TableDataInfo list(WaterUserMeterVO userMeterVO)
    {
        startPage();
        userMeterVO.setMeterType("0"); //水表类型为 远传表
        List<WaterUserMeterVO> list = waterUserService.selectWaterUserMeterList(userMeterVO);
        return getDataTable(list);
    }

    /**
     * 查询周用水量汇总列表
     */
    @PreAuthorize("@ss.hasPermi('meterread:weekusage:hisList')")
    @GetMapping("/hisList")
    public TableDataInfo list(WaterWeeklyUsage waterWeeklyUsage)
    {
        startPage();
        List<WaterWeeklyUsage> list = waterWeeklyUsageService.selectWaterWeeklyUsageList(waterWeeklyUsage);
        return getDataTable(list);
    }

    /**
     * 导出周用水量汇总列表
     */
    @PreAuthorize("@ss.hasPermi('meterread:weekusage:export')")
    @Log(title = "周用水量汇总", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WaterWeeklyUsage waterWeeklyUsage)
    {
        List<WaterWeeklyUsage> list = waterWeeklyUsageService.selectWaterWeeklyUsageList(waterWeeklyUsage);
        ExcelUtil<WaterWeeklyUsage> util = new ExcelUtil<WaterWeeklyUsage>(WaterWeeklyUsage.class);
        util.exportExcel(response, list, "周用水量汇总数据");
    }

    /**
     * 获取周用水量汇总详细信息
     */
    @PreAuthorize("@ss.hasPermi('meterread:weekusage:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(waterWeeklyUsageService.selectWaterWeeklyUsageById(id));
    }

    /**
     * 新增周用水量汇总
     */
    @PreAuthorize("@ss.hasPermi('meterread:weekusage:add')")
    @Log(title = "周用水量汇总", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WaterWeeklyUsage waterWeeklyUsage)
    {
        return toAjax(waterWeeklyUsageService.insertWaterWeeklyUsage(waterWeeklyUsage));
    }

    /**
     * 修改周用水量汇总
     */
    @PreAuthorize("@ss.hasPermi('meterread:weekusage:edit')")
    @Log(title = "周用水量汇总", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WaterWeeklyUsage waterWeeklyUsage)
    {
        return toAjax(waterWeeklyUsageService.updateWaterWeeklyUsage(waterWeeklyUsage));
    }

    /**
     * 删除周用水量汇总
     */
    @PreAuthorize("@ss.hasPermi('meterread:weekusage:remove')")
    @Log(title = "周用水量汇总", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(waterWeeklyUsageService.deleteWaterWeeklyUsageByIds(ids));
    }
}
